#!/bin/bash

# Script to copy HTML files to running nginx pod's PVC
# Usage: ./copy-html-to-pvc.sh

echo "🔍 Finding nginx pod..."
POD_NAME=$(kubectl get pods -l app=nginx -o jsonpath='{.items[0].metadata.name}')

if [ -z "$POD_NAME" ]; then
    echo "❌ No nginx pod found. Make sure the deployment is running."
    exit 1
fi

echo "📦 Found pod: $POD_NAME"

# Copy HTML files from local directory to pod
echo "📁 Copying HTML files to pod..."
kubectl cp ./html/ $POD_NAME:/usr/share/nginx/

if [ $? -eq 0 ]; then
    echo "✅ HTML files copied successfully!"
    echo "🌐 You can now access your custom HTML at http://localhost:30080"
else
    echo "❌ Failed to copy HTML files"
    exit 1
fi

# Optionally restart the deployment to ensure changes are picked up
echo "🔄 Restarting deployment to ensure changes are loaded..."
kubectl rollout restart deployment/nginx-deployment

echo "✅ All done! Your custom HTML should now be served."
